package business;
import java.util.ArrayList;

import persistence.*;

/*
 * Singleton Class
 */
public class BookingBook 
{
	//member variables
	private ArrayList<Booking> Bookings;
	private static BookingBook Instance;
	
	private BookingBook()
	{
		Bookings = new ArrayList<Booking>(30);
		LoadFromStorage();
	}
	

	//methods
	/*
	 * Singleton Class Method
	 */
	public static BookingBook GetInstance()
	{
		if(Instance==null)
		{
			Instance = new BookingBook();
			return Instance;
		}
		
		else
		{
			return Instance;
		}
	}
	
	/*
	 * 
	 */
	private void LoadFromStorage()
	{
		ArrayList<BookingFascade> temp;
		temp = BookingTDG.FindAll();
		EventBook EventBookInstance = EventBook.GetInstance();
		CustomerBook CustomerBookInstance = CustomerBook.GetInstance();

		for(BookingFascade BF : temp)
		{
			
			Event EventRegistered = EventBookInstance.Find(BF.getEventID());
			Customer CustomerAssociated = CustomerBookInstance.Find(BF.getCustomerID());
			Bookings.add(new Booking(CustomerAssociated,BF.getTotalPpl(),EventRegistered));
			
		}	
	}
	
	/*
	 * 
	 */
	public int GetTotalBookingsPerEventName(int EventID)
	{
		int Counter=0;
		
		for(Booking B : Bookings)
		{
			if(B.getEventRegistered().getID() == EventID)
			{
				Counter++;
			}
		}
		return Counter;
	}


	public ArrayList<Booking> getBookings() {
		return Bookings;
	}


	public void setBookings(ArrayList<Booking> bookings) {
		Bookings = bookings;
	}


	public static BookingBook getInstance() {
		return Instance;
	}


	public static void setInstance(BookingBook instance) {
		Instance = instance;
	}
	
	
}
